simple_mod_code <- "data {

int<lower = 0> N_obs;                 // Observations
int<lower = 0> N_MPs;           // MPs
int<lower = 0> N_terms;           // Terms
int<lower = 0> N_debates;           // Debates
int<lower = 0> N_ind_covars;           // Covariates
real R_Y[N_obs];
int<lower = 0, upper = 1> Ri_gender[N_MPs];
int<lower = 1, upper = N_MPs> R_mp_id[N_obs];
int<lower = 1, upper = N_debates> R_debate_id[N_obs];
int<lower = 1, upper = N_terms> Ri_term[N_MPs];
real sigma_prior_variance;
real sigma_alpha_prior_variance;
real sigma_delta_prior_variance;
matrix[N_MPs, N_ind_covars] X_ind;

}

parameters {

real delta[N_debates];                // Debate effects

real alpha_raw[N_MPs];                    // MP effects

real alpha_intercept[N_terms];                       // Baseline for each time period
real alpha_gender_effect[N_terms];           // Effect for gender for each time period

vector[N_ind_covars] Beta; 

real<lower = 0> sigma;                  // Variance on response
real<lower = 0> sigma_alpha;            // Variance on MP effects
real<lower = 0> sigma_delta;            // Variance on debate effects
real<lower = 0> sigma_random_walk_gender;            // Variance on second-level gender-effects
real<lower = 0> sigma_random_walk_intercept;            // Variance on second-level intercepts

}

transformed parameters {

real alpha[N_MPs];

for(i in 1:N_MPs) {
    alpha[i] = alpha_intercept[Ri_term[i]] + 
                alpha_gender_effect[Ri_term[i]] * Ri_gender[i] + 
                dot_product(Beta, X_ind[i,]) +
                sigma_alpha * alpha_raw[i];
}

}

model {

// Priors for alpha

alpha_raw ~ std_normal();

// Priors for second-level alpha

for(i in 2:N_terms) alpha_gender_effect[i] ~ normal(alpha_gender_effect[i-1], sigma_random_walk_gender);
for(i in 2:N_terms) alpha_intercept[i] ~ normal(alpha_intercept[i-1], sigma_random_walk_intercept);

// Priors for delta

delta ~ normal(0, sigma_delta);

// Priors for Beta

Beta ~ normal(0, 2);

// Variance priors

sigma ~ normal(0, sigma_prior_variance);
sigma_alpha ~ normal(0, sigma_alpha_prior_variance);
sigma_delta ~ normal(0, sigma_delta_prior_variance);

// Model for outcome

{

vector[N_obs] lin_pred;

for(i in 1:N_obs) lin_pred[i] = alpha[R_mp_id[i]] + delta[R_debate_id[i]];

R_Y ~ normal(lin_pred, sigma);

}

}"